from db.mysql import mysql

async def get_user_images(userId: str):
    """获取用户的图片生成记录"""
    query = "SELECT * FROM image WHERE userId = %s ORDER BY createdAt DESC"
    return await mysql.fetch_all(query, (userId,))

async def clear_user_images(userId: str):
    """清空用户的图片生成记录"""
    query = "DELETE FROM image WHERE userId = %s"
    result = await mysql.execute(query, (userId,))
    return result

async def save_image_record(userId: str, description: str, generatedUrl: str):
    """保存图片生成记录"""
    query = """
        INSERT INTO image 
        (userId, description, generatedUrl, createdAt) 
        VALUES (%s, %s, %s, NOW())
    """
    return await mysql.execute(query, (userId, description, generatedUrl))